package Obstacle;

import static org.junit.Assert.*;


import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import Enumerations.Directions;

import squarePackage.PlainSquare;
import squarePackage.Square;

/**
 * @version 24/3/2011 20.42
 * @author Pieter & An
 *
 */

public class ObstacleTest {
	
	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	private Wall wall;
	private Door door;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		wall = new Wall();
		door = new Door();
		
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public final void setDoor(){
		wall.setDoor(door);
		assertEquals(door,wall.getDoor());
	}
	
	@Test
	public final void newDoor(){
		Door door = new Door(wall);
		assertEquals(door,wall.getDoor());
	}
	
	@Test
	public final void wallWithDoor(){
		Wall testWall = new Wall(new Door());
		assertTrue(testWall.hasDoor());
	}
	
	@Test
	public final void setDoorAlreadyWall(){
		Door door = new Door(new Wall());
		wall.setDoor(door);
		assertFalse(wall.hasDoor());
	}
	
	@Test 
	public final void newDoorAlreadyDoor(){
		wall.setDoor(door);
		Door testDoor = new Door(wall);
		assertFalse(testDoor.hasWall());
	}
	
	@Test 
	public final void newDoorAlreadyDoorTerminated(){
		wall.setDoor(door);
		Door testDoor = new Door(wall);
		assertTrue(testDoor.isTerminated());
	}
	
	@Test 
	public final void newWallAlreadyWallTeminated(){
		Door testDoor = new Door(wall);
		Wall testWall = new Wall(testDoor);
		assertTrue(testWall.isTerminated());
	}
	
	@Test
	public final void setWallTestDoor(){
		door.setWall(wall);
		assertEquals(wall, door.getWall());
	}
	@Test
	public final void setWallTestWall(){
		door.setWallToDoor(wall);
		assertEquals(door, wall.getDoor());
	}
	
	@Test
	public final void removeDoor(){
		wall.setDoor(door);
		wall.removeDoor();
		assertFalse(wall.hasDoor());
	}
	
	@Test
	public final void removeDoorIsTerminated(){
		wall.setDoor(door);
		wall.removeDoor();
		assertTrue(door.isTerminated());
	}
	
	@Test
	public final void terminateWallWithDoor(){
		wall.setDoor(door);
		wall.terminate();
		assertTrue(door.isTerminated());
	}
	
	@Test
	public final void terminateWallWithoutDoor(){
		wall.terminate();
		assertTrue(wall.isTerminated());
	}
	
	@Test
	public final void createOpenDoor(){
		wall.setDoor(new Door(true, wall));
		assertTrue(wall.getDoor().isOpen());
	}
	
	@Test
	public final void createWallWithOpenDoor(){
		Wall newWall = new Wall();
		newWall.setDoor(new Door(true, newWall));
		assertTrue(newWall.getDoor().isOpen());
	}
	
	@Test
	public final void createWallWithDoor(){
		Wall newWall = new Wall(new Door());
		assertFalse(newWall.getDoor().isOpen());
	}
	
	@Test
	public final void checkIdeaArrayTest(){
		Square square = new PlainSquare();
		assertEquals(6,square.getBorders().length);
	}
	
	@Test
	public final void setWallToSquare(){
		Square square = new PlainSquare();
		Wall newWall = new Wall();
		square.setBorder(Directions.East, newWall);
		assertEquals(square,newWall.getSquare1());
		assertEquals(newWall,square.getBorderByDirection(Directions.East));
	}
	
	@Test
	public final void setWallToSquare2(){
		Square square1 = new PlainSquare();
		Square square2 = new PlainSquare();
		Wall newWall = new Wall();
		square1.setBorder(Directions.East, newWall);
		square2.setBorder(Directions.West,newWall);
		assertEquals(square1,newWall.getSquare1());
		assertEquals(square2,newWall.getSquare2());	
	}
	
	@Test
	public final void setSecondWall(){
		Square square = new PlainSquare();
		Wall secondWall = new Wall();
		square.setBorder(Directions.East, wall);
		square.setBorder(Directions.East, secondWall);
		assertTrue(wall.isTerminated());
	}

	@Test
	public final void deleteBorder(){
		Square square = new PlainSquare();
		square.setBorder(Directions.East, wall);
		square.deleteBorder(Directions.East);
		assertTrue(wall.isTerminated());
	}

	@Test
	public final void hasNumberOfDoors(){
		Square square = new PlainSquare();
		square.setBorder(Directions.East, new Wall(new Door()));
		square.setBorder(Directions.North, new Wall(new Door()));
		assertEquals(2,square.hasNumberOfDoors());
	}
}

